package com.kun.demo03;

import org.junit.Test;

//测试线程停止
public class TestThreadStop implements Runnable {

    Boolean flag = true;


    @Override
    public void run() {
        while (flag) {
            System.out.println("线程正在运行");
        }
        System.out.println("线程停止了");
    }

    public void stopThread(){
        flag = false;
    }

    @Test
    public void testThreadStop(){
        Thread thread = new Thread(this);
        thread.start();
        for (int i = 0; i < 100; i++) {
            System.out.println("主线程运行");
            if (i == 99){
                stopThread();
            }
        }
    }
}
